package com.example.springboot.utils;

import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: wyb
 * @date: 2021/10/31 17:37
 * @describe:
 * @vision 1.0
 */
public class BeanConvertor {
    private final static Mapper mapper = new DozerBeanMapper();

    public static <T, S> List<T> convertor(List<S> source, Class<T> clz) {
        if (source == null) return null;
        List<T> map = new ArrayList<>();
        for (S s : source) {
            map.add(mapper.map(s, clz));
        }
        return map;
    }

    public static <T, S> T convertor(S source, Class<T> clz) {
        if (source == null) return null;
        return mapper.map(source, clz);
    }

}
